#include "KRuntime.h"
#include "KMemory.h"
#include "KStream.h"

namespace krt
{
	stream::size_type stream::GetPosition()
	{
		return this->seek(0, soFromCurrent);
	}

	void stream::SetPosition(size_type NewPos)
	{
		this->seek(NewPos, soFromBeginning);
	}

	stream::size_type stream::GetSize()
	{
		size_type bookmark = this->GetPosition();
		size_type result = this->seek(0, soFromEnd);
		this->seek(bookmark, soFromBeginning);
		return result;
	}

	void stream::SetSize(size_type NewSize)
	{
		size_type bookmark = this->GetPosition();
		this->seek(NewSize, soFromBeginning);
		this->SetEnd();
		this->seek(bookmark, soFromBeginning);
	}

	/// MemoryStream

	MemoryStream::~MemoryStream()
	{
		if (m_buf)
			m_MemMgr->free(m_buf);
	}

	void MemoryStream::SetEnd()
	{
		m_size = m_pos;
	}

	stream::size_type MemoryStream::seek(offset_type offset, SeekOrigin origin)
	{
		return 0;
	}

	size_t MemoryStream::read(void* buf, size_t BufSize)
	{
		return 0;
	}

	size_t MemoryStream::write(const void* buf, size_t BufSize)
	{
		return 0;
	}
}
